package com.niuke;

import com.leetCode.tree.TreeNode;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-11-24 10:03:47
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-11-24     张李鑫                     1.0         1.0 Version
 */
public class NC16 {
    /**
     * 给定一棵二叉树，判断其是否是自身的镜像（即：是否对称）
     * 例如：下面这棵二叉树是对称的
     */


    private static StringBuffer pre(TreeNode root, StringBuffer result) {
        if (root == null) {
            result.append("#");
            return result;
        }
        pre(root.left, result);
        pre(root.right, result);
        result.append(root.val);
        return result;
    }


    private static StringBuffer pre1(TreeNode root, StringBuffer result) {
        if (root == null) {
            result.append("#");
            return result;
        }
        pre1(root.right, result);
        pre1(root.left, result);
        result.append(root.val);
        return result;
    }


    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(2);

        treeNode.left = treeNode2;

        StringBuffer stringBuffer = new StringBuffer();
        System.out.println(pre(treeNode, stringBuffer).toString());
        System.out.println();
        System.out.println(pre1(treeNode, new StringBuffer()));

    }

    boolean isSymmetrical(TreeNode pRoot) {
        if (pRoot == null) {
            return true;
        }

        return pre(pRoot, new StringBuffer()).toString().equals(pre1(pRoot, new StringBuffer()).toString());
    }
}
